/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package workforce.limousine.service;

import java.util.List;
import limousine.vo.Customer;
import org.jsrpc.servlet.SessionBean;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.workforce.util.Utils;

/**
 *
 * @author Neo
 */
public class CustomerManager extends SessionBean {
    
    private Service service = null; 
    
    public CustomerManager() {
      
    }
    
    public void init() {
        if (service == null) {
            service = (Service) WebApplicationContextUtils.getWebApplicationContext(
                    this.getServletContext()).getBean("customerService");
        }
    }
    
    public boolean remove(String customerId) {
        init();
        return service.remove(customerId);
    }
    
    public boolean save(Customer customer) {
        init();
        return service.save(customer);
    }
    public List<Customer> search(int offset, String token) {
        init();
        //System.out.println("limit :"+ properties.getProperty("ui.limit") );
        //int limit = Integer.parseInt(properties.getProperty("ui.limit", "20"));
        List<Customer> list = service.search(offset, new Object[]{token});
        return list;
    }
    public boolean update(Customer customer) {
        init();
        return service.update(customer);
    }
    
    public Customer findById(String id) {
        init();
        return (Customer)service.findById(id);
    }

    public Service getCustomerService() {
        return service;
    }

    public void setCustomerService(Service service) {
        this.service = service;
    }
    
    public String requestId() {
        return Utils.generateId();
    }
    

}
